//
//  ZFListViewController.m
//  ZFDownload
//
//  Created by 任子丰 on 16/5/16.
//  Copyright © 2016年 任子丰. All rights reserved.
//

#import "ZFListViewController.h"
#import "ZFDownloadManager.h"
#import "ZFListCell.h"

@interface ZFListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic  ) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@end

@implementation ZFListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.dataSource = @[@"http://dldir1.qq.com/qqfile/QQforMac/QQ_V4.2.4.dmg",
                        @"https://zyk.singaporeinfo-edu.com/upfiles/vod/20211224094910_549.mp4",
                        @"https://zyk.singaporeinfo-edu.com/upfiles/vod/20211224095154_679.mp4",
                        @"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4",
                        @"https://zyk.singaporeinfo-edu.com/upfiles/vod/20211224145306_910.mp4",
                        @"https://zyk.singaporeinfo-edu.com/upfiles/vod/20211224094132_204.mp4"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZFListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"listCell"];
    __block NSString *urlStr = self.dataSource[indexPath.row];
    cell.titleLabel.text = urlStr;
    cell.downloadCallBack = ^{
        // 此处是截取的下载地址，可以自己根据服务器的视频名称来赋值
        NSString *name = [[urlStr componentsSeparatedByString:@"/"] lastObject];
        [[ZFDownloadManager sharedDownloadManager] downFileUrl:urlStr filename:name fileimage:nil];
        // 设置最多同时下载个数（默认是3）
        [ZFDownloadManager sharedDownloadManager].maxCount = 2;
    };
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
